TKey
TValue
CSharpTest.Net
TransactionLogOptions<TKey,TValue> Class
Members  Example  See Also  Send Feedback Download Help File
CSharpTest.Net.BPlusTree Assembly > CSharpTest.Net.Collections Namespace : TransactionLogOptions<TKey,TValue> Class

Glossary Item Box

Options used to initialize a TransactionLog

Syntax

Visual Basic (Declaration) 
Public Class TransactionLogOptions
    (Of TKey,TValue) 
C# 
public class TransactionLogOptions<TKey,TValue> 

Type Parameters

TKey
TValue

Example

BPlusTree/BPlusTree.Test/TestTransactionLog.cs

C#Copy Code
//Write 2,147,483,776 bytes in: 00:02:09.7934237 (in chunks of 128 bytes)
//Write 4,295,032,832 bytes in: 00:00:18.4990581 (in chunks of 65536 bytes)
//Logged 2,398,000,000 bytes in: 00:00:36.7621027


string newpath = Path.Combine(@"C:\Temp\LogTest\", Guid.NewGuid() + ".tmp");
using (TempFile tmp = TempFile.Attach(newpath))
{
    byte[] bytes;
    DateTime start;
    //bytes = new byte[128];
    //new Random().NextBytes(bytes);

    //start = DateTime.UtcNow;
    //using (var io = new FileStream(tmp.TempPath, FileMode.Append, FileAccess.Write, FileShare.Read, 8))
    //{
    //    for (int i = 0; i <= 16777216; i++)
    //        io.Write(bytes, 0, 128);
    //}
    //Console.WriteLine("Write {0:n0} bytes in: {1}", tmp.Length, DateTime.UtcNow - start);
    //tmp.Delete();

    var options = new TransactionLogOptions<Guid, byte[]>(
        tmp.TempPath, PrimitiveSerializer.Guid, PrimitiveSerializer.Bytes) 
        {
            FileBuffer = ushort.MaxValue,
            FileOptions = FileOptions.None | FileOptions.SequentialScan,
        };

    Guid[] ids = new Guid[1000000];
    for (int i = 0; i < ids.Length; i++)
        ids[i] = Guid.NewGuid();

    bytes = new byte[100];
    new Random().NextBytes(bytes);

    start = DateTime.UtcNow;

    using (var log = new TransactionLog<Guid, byte[]>(options))
    {
        foreach(Guid id in ids)
        {
            var token = log.BeginTransaction();
            for (int i = 0; i < 20; i++)
                log.AddValue(ref token, id, bytes);
            log.CommitTransaction(ref token);
        }
    }

    Console.WriteLine("Logged {0:n0} bytes in: {1}", tmp.Length, DateTime.UtcNow - start);
}
VB.NETCopy Code
'Write 2,147,483,776 bytes in: 00:02:09.7934237 (in chunks of 128 bytes)
'Write 4,295,032,832 bytes in: 00:00:18.4990581 (in chunks of 65536 bytes)
'Logged 2,398,000,000 bytes in: 00:00:36.7621027


Dim newpath As String = Path.Combine("C:\Temp\LogTest\", Guid.NewGuid() + ".tmp")
Using tmp As TempFile = TempFile.Attach(newpath)
    Dim bytes As Byte()
    Dim start As DateTime
    'bytes = new byte[128];
    'new Random().NextBytes(bytes);

    'start = DateTime.UtcNow;
    'using (var io = new FileStream(tmp.TempPath, FileMode.Append, FileAccess.Write, FileShare.Read, 8))
    '{
    '    for (int i = 0; i <= 16777216; i++)
    '        io.Write(bytes, 0, 128);
    '}
    'Console.WriteLine("Write {0:n0} bytes in: {1}", tmp.Length, DateTime.UtcNow - start);
    'tmp.Delete();

    Dim options As var = New TransactionLogOptions(Of Guid, Byte())(tmp.TempPath, PrimitiveSerializer.Guid, PrimitiveSerializer.Bytes) With { _
        Key .FileBuffer = UShort.MaxValue, _
        Key .FileOptions = FileOptions.None Or FileOptions.SequentialScan _
    }

    Dim ids As Guid() = New Guid(1000000) {}
    Dim i As Integer = 0
    While i < ids.Length
        ids(i) = Guid.NewGuid()
        System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
    End While

    bytes = New Byte(100) {}
    New Random().NextBytes(bytes)

    start = DateTime.UtcNow

    Using log As var = New TransactionLog(Of Guid, Byte())(options)
        For Each id As Guid In ids
            Dim token As var = log.BeginTransaction()
            Dim i As Integer = 0
            While i < 20
                log.AddValue(token, id, bytes)
                System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
            End While
            log.CommitTransaction(token)
        Next
    End Using

    Console.WriteLine("Logged {0:n0} bytes in: {1}", tmp.Length, DateTime.UtcNow - start)
End Using

Inheritance Hierarchy

System.Object
   CSharpTest.Net.Collections.TransactionLogOptions<TKey,TValue>

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys